#include<iostream>
#include<algorithm>
using namespace std;
#include<fstream>



ifstream in("in.txt");

//直接递归求解
int getMinNum(int S,int i,int Arr[],int N)
{ 
    int ret;
    if(S == 0) {
        return 0;
    }
    if(i == N) {
        ret = S == 0 ? 0 : -1;
        cout << "f(" << S << "," << i << ")" << endl;
        cout << ret << endl;
        return ret;
    }
    if(S >= Arr[i]) {
        int p1 = getMinNum(S-Arr[i],i+1,Arr,N);
        int p2 = getMinNum(S,i+1,Arr,N);
        if(p1 == -1 && p2 == -1) {
            cout << "f(" << S << "," << i << ")" << endl;
            cout << -1 << endl;
            return -1;
        }
        if(p2 == -1) {
            cout << "f(" << S << "," << i << ")" << endl;
            cout << p1 + 1 << endl;
            return p1+1;
        }
        if(p1 == -1) {
            cout << "f(" << S << "," << i << ")" << endl;
            cout << p2 << endl;
            return p2;
        }
        cout << "f(" << S << "," << i << ")" << endl;
        cout << min(p1+1,p2) << endl;
        return min(p1+1,p2);
    } else {
        if(S == 8 && i == 2) {
            cout << "error" << endl;
        }
        int my = getMinNum(8,3,Arr,N);
        cout << "........." << my << endl;
        ret = getMinNum(S,i+1,Arr,N);

        if(S == 8 && i == 2) {
            cout << "out " << S << " " << i+1 << endl;
            cout << "error out:" << ret << endl;
        }
        // cout << "f(" << S << "," << i << ")" << endl;
        // cout << ret << endl;
        return ret;
    }
}

int myRec(int S,int i,int Arr[],int N)
{
    if(S == 0) {
        return 0;
    }
    if(i == N) {
        return S == 0 ? 0 : -1;
    }

    if(S >= Arr[i]) {
        int pSelect = myRec(S-Arr[i],i+1,Arr,N);
        int pNotSelect = myRec(S,i+1,Arr,N);
        if(pSelect == -1 && pNotSelect == -1) {
            return -1;
        }
        if(pSelect == -1) {
            return pNotSelect;
        }
        if(pNotSelect == -1) {
            return pSelect+1;
        }
        return min(pSelect+1,pNotSelect);
    } else {
        return myRec(S,i+1,Arr,N);
    }
}

int myRecMem(int S,int i,int Arr[],int N,int dp[][30])
{
    if(dp[S][i] != -2) {
        return dp[S][i];
    }
    if(S == 0) {
        dp[S][i] = 0;
        return dp[S][i];
    }
    if(i == N) {
        dp[S][i] = S == 0 ? 0 : -1;
        return dp[S][i];
    }

    if(S >= Arr[i]) {
        int pSelect = myRec(S-Arr[i],i+1,Arr,N);
        int pNotSelect = myRec(S,i+1,Arr,N);
        if(pSelect == -1 && pNotSelect == -1) {
            dp[S][i] = -1;
            return dp[S][i];
        }
        if(pSelect == -1) {
            dp[S][i] = pNotSelect;
            return dp[S][i];
        }
        if(pNotSelect == -1) {
            dp[S][i] = pSelect+1;
            return dp[S][i];
        }
        dp[S][i] = min(pSelect+1,pNotSelect);
        return dp[S][i];
    } else {
        dp[S][i] = myRec(S,i+1,Arr,N);
        return dp[S][i];
    }
}

int mydp(int S,int i,int Arr[],int N,int dp[][30])
{
    for(int k=0; k<N; k++) {
        dp[0][k] = 0;
    }
    for(int k=0; k<=S; k++) {
        dp[k][N] = -1;
    }
    dp[0][N] = 0;

    for(int k=N-1; k>=0; k--) {
        for(int j=1; j<=S; j++) {
            if(j >= Arr[k]){
                // cout << j << " ---> " << k << endl;
                int pSelect = dp[j-Arr[k]][k+1];
                int pNotSelect = dp[j][k+1];
                // cout << pSelect << " " << pNotSelect << endl;
                // exit(-1);
                if(pSelect == -1 && pNotSelect == -1) {
                    dp[j][k] = -1;
                } else if(pSelect == -1) {
                    dp[j][k] = pNotSelect;
                } else if(pNotSelect == -1) {
                    // cout << j << " ---> " << k << endl;
                    dp[j][k] = pSelect+1;
                    // exit(-1);
                } else {
                    dp[j][k] = min(pSelect+1,pNotSelect);
                }
            } else {
                dp[j][k] = dp[j][k+1];
            }
        }
    }
    return dp[S][N-1];
}

int mydp2(int S,int Arr[],int N)
{
    int dp[110][30];
    //填补最后一列
    for(int i=0; i<=S; i++) {
        dp[i][N] = -1;
    }
    dp[0][N] = 0;
    //从倒数第二列依次往前填补
    for(int i=N-1; i>=0; i--) {
        for(int j=0; j<=S; j++) {
            if(j-Arr[i] < 0) {
                dp[j][i] = dp[j][i+1];
            } else {
                int pSelect = dp[j-Arr[i]][i+1];
                int pNotSelet = dp[j][i+1];
                if(pSelect == -1 && pNotSelet == -1){
                    dp[j][i] = -1;
                } else if(pSelect == -1) {
                    dp[j][i] = pNotSelet;
                } else if(pNotSelet == -1) {
                    dp[j][i] = pSelect+1;
                } else {
                    dp[j][i] = min(pSelect+1,pNotSelet);
                }
            }
        }
    }
    int ret = dp[S][0] != -1 ? dp[S][0] : 0;
    return ret;
}


int main() {
    //余额 硬币数 面值数组
    int S,N,Arr[50];
    in >> S >> N;
    for(int i=0; i<N; i++) {
        in >> Arr[i];
    }

    int ret = mydp2(S,Arr,N);
    cout << ret << endl;
 
    //dp[S][i]
    // int dp[110][30];
    // for(int i=0; i<110; i++) {
    //     for(int j=0; j<30; j++) {
    //         dp[i][j] = -2;
    //     }
    // }
    // // int ret = myRec(S,0,Arr,N);
    // // int ret = myRecMem(S,0,Arr,N,dp);
    // int ret = mydp(S,0,Arr,N,dp);
    // for(int i=0; i<=S; i++) {
    //     for(int j=0; j<=N; j++) {
    //         cout << dp[i][j] << "\t";
    //     }
    //     cout << endl;
    // }
    // cout << ret << endl;
    return 0;
}